home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_309 / sksh / technotes.doc < prev    next >
Text File  |  1992-05-06  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.                                    Technical Notes
  17.  
  18.                                         SKSH
  19.  
  20.                            A ksh-like Shell for the Amiga
  21.  
  22.                                      Version 1.3
  23.  
  24.  
  25.                                (Copyright) 1989, 1990
  26.  
  27.                                      Steve Koren
  28.  
  29.                                    January 2, 1990
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.           Implementation Notes
  74.  
  75.             SKsh is the result of over 3 month's  of  evening  and  weekend
  76.             work on an Amiga 2000 with a Xetec  hard  disk  controller,  an
  77.             85mb Seagate drive, a CMI 14 mHz 68000 accelerator  board,  and
  78.             3mb  of  ram.   The  parser,  lexical  analyzer,  and   program
  79.             architecture were completed very quickly; most of the time  was
  80.             spent trying to figure out how  to  do  Amiga  specific  things
  81.             (like directories) and working around compiler bugs.
  82.  
  83.             SKsh has a parser that  was  generated  using  Amiga  yacc  and
  84.             modified by hand to deal with some  special  features  of  SKsh
  85.             (such as  command  substitution).   The  lexical  analyzer  was
  86.             written by hand, since I needed some capabilities  not  present
  87.             in Lex.  SKsh is composed of 50 .c files ranging  from  100  to
  88.             1300 lines, 23 function prototype files, 21 .h files,  and  one
  89.             .y (yacc) file.  The source  code  is  currently  around  17700
  90.             lines, not including test scripts.
  91.  
  92.             Internally, SKsh uses hash tables to keep track  of  variables,
  93.             aliases, functions, and keywords.  A stack of  hash  tables  is
  94.             maintained, and each time a function  is  called,  a  new  hash
  95.             table  is  pushed  onto  the  stack.   Then,  when  a  name  is
  96.             referenced, it is looked up in the hash  table  stack  starting
  97.             with the most recent hash table.  When a  function  exits,  the
  98.             most recent  hash  table  is  popped  off  the  stack  and  its
  99.             contents are freed.  Hash  table  entries  have  an  associated
  100.             type (variable, function, etc),  and  a  value,  which  can  be
  101.             either a text  string  (such  as  an  alias  definition)  or  a
  102.             pointer to a parse tree (for a function).
  103.  
  104.             SKsh was written  to  be  reentrant,  so  that  in  the  future
  105.             interprocess pipes may be used between  internal  and  external
  106.             commands.  Thus, all evaluation is done using only  information
  107.             passed around in an "EVAL_PACKET" structure so that no  globals
  108.             are referenced.  Each  execution  of  the  command  interpreter
  109.             generates its own hash table stack, its own  pointer  to  input
  110.             and output files, etc.  The few parts of  SKsh  which  are  not
  111.             reentrant  are  written   using   a   semaphore-based   locking
  112.             mechanism.  This locking mechanism is intelligent; it does  not
  113.             lock out all other tasks  from  the  system  (as  Forbit()  and
  114.             Permit() do), but simply allows only a single task  to  execute
  115.             a given section of program code at one time.
  116.  
  117.             All output is done through a single low  level  routine  which,
  118.             given an EVAL_PACKET and some text, will route it to  either  a
  119.             file or a string (in the  case  of  command  substition).   The
  120.             length of the space allocated for this string is  kept  in  the
  121.             EVAL_PACKET, and if the new text  would  cause  the  string  to
  122.             overflow its allocated space, more space is allocated  and  the
  123.             original  is  copied  into  the  new  space.    Thus,   command
  124.             substition and variables can  deal  with  text  of  any  length
  125.             limited only by free memory.
  126.  
  127.  
  128.  
  129.           SKSH Amiga Shell             Page 2              Technical Notes
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.             There are no hard-coded  branches  to  routines  which  execute
  140.             SKsh  builtin  commands.   A  single  structure  contains   all
  141.             necessary information for  builtin  commands,  including  their
  142.             name, a pointer to their execution routine,  and  a  few  other
  143.             things.  This architecture makes it trivial to add new  builtin
  144.             commands.  Keywords are dealt with in the same way.
  145.  
  146.             A series of test scripts  is  run  whenever  SKsh  is  changed.
  147.             These scripts test all  the  SKsh  commands  and  syntax.   The
  148.             output of these tests are compared against known  good  results
  149.             to verify that  no  previously  working  commands  were  broken
  150.             inadvertantly.  The entire series  of  25  test  scripts  takes
  151.             about 10 minutes to run on a stock 7.x mHz Amiga  2000.   There
  152.             are currently about 3400 lines of test scripts.
  153.  
  154.             Since the entire SKsh project was implemented on an Amiga,  and
  155.             SKsh was designed for Amigas, it  currently  runs  only  there.
  156.             It was, however, designed with machine  independence  in  mind.
  157.             The  machine  specific  code  is  enclosed  in   #ifdef   AMIGA
  158.             statements,  and  could  conceivably  be  replaced  with   code
  159.             specific to another machine.
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.           SKSH Amiga Shell             Page 3              Technical Notes
  196.  
  197.  
  198.  
  199.